package com.roger.tool.utils.mm;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import android.content.Context;

public class ApkUtils {

	public static String readXml(Context context, String packageName, String fileName) {
		String ret = null;
		try {

			ZipFile zipapk = new ZipFile(context.getPackageCodePath());
			ZipEntry entry = zipapk.getEntry(fileName);
			InputStream ips = zipapk.getInputStream(entry);
			byte[] fileData = readData(ips);
			ret = new String(fileData);
			ips.close();
		} catch (Exception e) {
//			e.printStackTrace();
		}
		return ret;
	}
	
	
	
	private static byte[] readData(InputStream ips){
		byte[] readArray = new byte[2046];
		int len;
		if(ips!=null){
			ByteArrayOutputStream byops = new ByteArrayOutputStream();
			try {
				while((len=ips.read(readArray))>0){
					byops.write(readArray, 0, len);
				}
				byops.close();
				return byops.toByteArray();
			} catch (IOException e) {
			}
		}
		return null;
	}

}
